package com.frxuexi.park2209_2.video.viewmodel

import androidx.lifecycle.MutableLiveData
import com.frxuexi.base.bean.SearchBean
import com.frxuexi.base.bean.VideoBean
import com.frxuexi.base.bean.VideoCommentBean
import com.frxuexi.base.bean.VideoCommentBeanItem
import com.frxuexi.base.db.VideoDao
import com.frxuexi.base.mvvm.BaseViewModel
import com.frxuexi.base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class VideoViewModel @Inject constructor(val apiService: ApiService,val videoDao: VideoDao):BaseViewModel() {

    var videosSuc =MutableLiveData<VideoBean>()

    var videoCommentSuc =MutableLiveData<VideoCommentBean>()

    var commentSuc =MutableLiveData<VideoCommentBean>()

    var searchSuc =MutableLiveData<VideoBean>()

    var addSearchSuc=MutableLiveData<Long>()
    var getSearchSuc=MutableLiveData<List<SearchBean>>()
    var deleteSuc=MutableLiveData<Int>()

    var zanSuc=MutableLiveData<String>()
    var nozanSuc=MutableLiveData<String>()
    var guanzhuSuc=MutableLiveData<String>()
    var noguanzhuSuc=MutableLiveData<String>()
    fun getVideos(page:Int){
        httpRequest({apiService.getVideos(page)},videosSuc::postValue)
    }

    fun getVideoComment(id:Int){
        httpRequest({apiService.getVideoComment(id)},videoCommentSuc::postValue)
    }

    fun comment(map: Map<String,Any>){
        httpRequest({apiService.comment(mapToBody(map))},commentSuc::postValue)
    }

    fun findVideoByName(key:String){
        httpRequest({apiService.findVideoByName(key)},searchSuc::postValue)
    }

    fun addSearch(searchBean: SearchBean){
        roomRequest({videoDao.insertVideo(searchBean)},addSearchSuc::postValue)
    }

    fun getSearch(){
        roomRequest({videoDao.selectInfo()},getSearchSuc::postValue)
    }

    fun deleteSearch(searchBean: SearchBean){
        roomRequest({videoDao.deleteInfo(searchBean)},deleteSuc::postValue)
    }

    fun love(vid:Int){
        httpRequest({apiService.love(vid)},zanSuc::postValue)
    }

    fun nolove(vid:Int){
        httpRequest({apiService.nolove(vid)},nozanSuc::postValue)
    }

    fun guanzhu(map: Map<String, String>){
        httpRequest({apiService.gaunzhu(mapToBody(map))},guanzhuSuc::postValue)
    }

    fun noguanzhu(map: Map<String, String>){
        httpRequest({apiService.noguanzhu(mapToBody(map))},noguanzhuSuc::postValue)
    }
}